unit uMeetingForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uAbstractDataTabForm, DB, DBActns, ActnList, ImgList, XPMan, Grids,
  DBGrids, StdCtrls, ExtCtrls, ComCtrls, ToolWin, Buttons, Mask,
  DBCtrls;

type
  TMeetingForm = class(TAbstractDataTabForm)
    Label1: TLabel;
    dbeMeetingID: TDBEdit;
    Label2: TLabel;
    dbeTopic: TDBEdit;
    Label4: TLabel;
    dbeDuaration: TDBEdit;
    Label5: TLabel;
    dbeData: TDBEdit;
    Label6: TLabel;
    dbeStartTime: TDBEdit;
    Label8: TLabel;
    dbeRoomName: TDBEdit;
    Label7: TLabel;
    dbeRoomID: TDBEdit;
    datSearch: TDataSource;
    datParticipants: TDataSource;
    lblSearch: TLabel;
    edtSearch: TEdit;
    butUserSearch: TBitBtn;
    dbgSearch: TDBGrid;
    dbgParticipants: TDBGrid;
    butUserAdd: TSpeedButton;
    butUserDel: TSpeedButton;
    butTimeRoomForm: TSpeedButton;
    panParticipants: TPanel;
    procedure FormDestroy(Sender: TObject);
    procedure butUserAddClick(Sender: TObject);
    procedure butUserDelClick(Sender: TObject);
    procedure datControlStateChange(Sender: TObject);
    procedure datParticipantsStateChange(Sender: TObject);
    procedure butUserSearchClick(Sender: TObject);
    procedure butTimeRoomFormClick(Sender: TObject);
    procedure datSearchStateChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fMeetingForm: TMeetingForm;

implementation
uses uMeetingControl;
{$R *.dfm}

procedure TMeetingForm.butTimeRoomFormClick(Sender: TObject);
var Time:TTime;
Room_ID:integer;
Room_Name:string;
begin
  inherited;
  if TMeetingControl.GetInstance.CreateTimeRoomForm(Time,Room_ID,Room_Name) then
  begin
    datControl.DataSet.FieldByName('STARTTIME').AsDateTime:=Time;
    datControl.DataSet.FieldByName('ROOM_ID').AsInteger:=Room_ID;
    datControl.DataSet.FieldByName('ROOM_NAME').AsString:=Room_Name;
  end;

end;

procedure TMeetingForm.butUserAddClick(Sender: TObject);
begin
  inherited;
  if datControl.State in [dsInsert,dsEdit] then
    begin
      datParticipants.DataSet.InsertRecord(
        [datControl.DataSet.FieldByName('MEETING_ID').AsInteger,
          datSearch.DataSet.FieldByName('USER_ID').AsInteger,
          datSearch.DataSet.FieldByName('USER_NAME').AsString]);
      datSearch.DataSet.Delete;
    end;
end;

procedure TMeetingForm.butUserDelClick(Sender: TObject);
begin
  inherited;
  if datControl.State in [dsInsert,dsEdit] then
  begin
    datSearch.DataSet.InsertRecord([datParticipants.DataSet.FieldByName('USER_ID').AsInteger,
      datParticipants.DataSet.FieldByName('USER_NAME').AsString]);
    datParticipants.DataSet.Delete;
  end;
end;

procedure TMeetingForm.butUserSearchClick(Sender: TObject);
begin
  inherited;
  TMeetingControl.GetInstance.LocateUser(edtSearch.Text);
end;

procedure TMeetingForm.datControlStateChange(Sender: TObject);
begin
  inherited;
  butUserAdd.Enabled:=(datControl.State in [dsInsert,dsEdit]) and not
      (datSearch.DataSet.IsEmpty);
  butUserDel.Enabled:=(datControl.State in [dsInsert,dsEdit])and not
      datParticipants.DataSet.IsEmpty;
end;

procedure TMeetingForm.datParticipantsStateChange(Sender: TObject);
begin
  inherited;
  butUserDel.Enabled:=(datControl.State in [dsInsert,dsEdit])and not
    (datParticipants.DataSet.IsEmpty);
end;

procedure TMeetingForm.datSearchStateChange(Sender: TObject);
begin
  inherited;
  butUserAdd.Enabled:=(datControl.State in [dsInsert,dsEdit]) and not (datSearch.DataSet.IsEmpty);
end;

procedure TMeetingForm.FormDestroy(Sender: TObject);
begin
  inherited;
  fMeetingForm:=nil;
end;

end.
